#include "MoveAnim.h"

MoveAnim::MoveAnim()
{
    deplGauche=true;
}

MoveAnim::~MoveAnim()
{
    //dtor
}

void MoveAnim::playMovement(Sprite& move)
{
   Clock horloge;
   int depl=0;
   int x, x2;
    if(deplGauche)
        {

            deplGauche = false;
        }
        else
        {

            deplGauche=true;
        }
    while(depl<QUAD_SIZE)
    {
        horloge.Reset();
        float fr = 0.f;
        while(fr < 1.0/64.0)
        {
            fr = horloge.GetElapsedTime();
        }
            if(deplGauche)
            {
                x = ((depl/16)%2)*32;
                x2 = x+32;
            }
            else
            {
                x= (((depl/16)%2)+2)*32;
                x2=x+32;
            }

        if(direction==0)
            move.Move(0,-1);
        else if(direction==1)
            move.Move(-1,0);
        else if(direction==2)
            move.Move(0,1);
        else
            move.Move(1,0);

        move.SetSubRect(IntRect( x, direction*32, x2, (direction*32)+QUAD_SIZE));
        depl++;
    }

    depl=0;
    move.SetSubRect(IntRect( (depl/8)*32, direction*32, ((depl/8)*32)+QUAD_SIZE, (direction*32)+QUAD_SIZE));


}

void MoveAnim::setDirection(int d)
{
    direction = d;
}

int MoveAnim::getDirection()
{
    return direction;
}
